package logic

import (
	"apple/models/mysql"
	"context"

	"apple/applerpc/applerpc"
	"apple/applerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderLogic {
	return &OrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 排行
func (l *OrderLogic) Order(in *applerpc.OrderRequest) (*applerpc.OrderResponse, error) {
	// todo: add your logic here and delete this line
	var activity []mysql.Activity
	mysql.DB.Debug().Limit(10).Order("class desc").Find(&activity)

	var aclist []*applerpc.AcList
	for _, i2 := range activity {
		list := applerpc.AcList{
			Image:     i2.Image,
			Name:      i2.Name,
			Publisher: i2.Publisher,
			Class:     i2.Class,
			Message:   i2.Message,
			UserId:    i2.UserId,
		}
		aclist = append(aclist, &list)
	}
	return &applerpc.OrderResponse{
		List: aclist,
	}, nil
}
